package org.malred.hospital.controller;

import org.malred.hospital.common.R;

import org.malred.hospital.entity.TbMedicineList;
import org.malred.hospital.entity.TbMedicineList;
import org.malred.hospital.entity.TbMedicineList;
import org.malred.hospital.service.MedicineListService;
import org.malred.hospital.service.MedicineListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/medicine-list")
public class MedicineListController extends BaseController<TbMedicineList> {
    @Autowired
    private MedicineListService service;

    @Override
    public R<List<TbMedicineList>> findAll() {
        return R.success(service.list());
    }

    @Override
    public R<TbMedicineList> findById(Long id) {
        return R.success(service.getById(id));
    }

    @Override
    public R<TbMedicineList> insert(@RequestBody TbMedicineList dto) {
        if (service.save(dto)) {
            return R.success(dto);
        } else {
            return R.error("添加 [MedicineList] 失败");
        }
    }

    @Override
    public R<TbMedicineList> update(@RequestBody TbMedicineList dto) {
        if (service.save(dto)) {
            return R.success(dto);
        } else {
            return R.error("修改 [MedicineList] 失败");
        }
    }

    @Override
    public R<TbMedicineList> delete(Long id) {
        if (service.removeById(id)) {
            return R.success(null);
        } else {
            return R.error("删除 [MedicineList] 失败");
        }
    }
}
